#pragma once

class CPOSPrinter
{
public:
    CPOSPrinter(int nType, int nPort);
    virtual ~CPOSPrinter() {}

    // Initialize printer
    virtual BOOL Initialize();
    // Print and feed a line
    virtual BOOL Print(LPCTSTR pStr, int nLength, int nColor = -1);

    virtual BOOL QueryStatus(int nUnit, int &nError) { return TRUE;}

    virtual void Recovery(int nMode) {}

    virtual void OpenCashdrawer(int nOpenInter = 0, int nCloseInter = 0) {}
    virtual int QueryCashdrawerStatus() {return 0; }

    virtual void SetCharsGap(int nGap) {}

    virtual void SetPrintMode(int nMode) {}

    virtual void SetPosition(int nL, int nH) {}

    virtual void SetUnderline(int nUL) {}

    virtual void SetDefualLineHight() {}

    virtual void SetLineHeight(int nHeight) {}

    virtual void EnablePrinter(BOOL bEnable = TRUE) {}

    virtual void Rotate(int nDegree) {}

    virtual void SetRelativePos(int nL, int nH) {}

    virtual void SetAlignmentMode(int nMode) {}

    virtual void EnableButton(BOOL bEnable = TRUE) {}

    virtual void PrintandFeed(LPCTSTR pStr, int nLength, int nFeed) {}

    virtual void SetCharSize(int nSize) {}

    virtual BOOL QueryPrinterID(int &nID) {return TRUE;}

    virtual void SetLeftGap(int nL, int nH) {} 

    virtual void SetUnit(int nX, int nY) {}

    virtual void CutPaper(int nMode) {}

    virtual void EnableBold(BOOL bEnable = TRUE) {}

    virtual void EnableUserFontSet(BOOL bEnabled = TRUE) {}

    virtual void SetUserFontSet(int nSet) {}

    virtual void SetBarcodeWidth(int nWidth) {}
    virtual void SetBarcodeHeight(int nHeight) {}
    virtual void PrintBarcode(){}

    virtual BOOL Close();
    
    int GetType() const {return m_nType;}
    int GetLastError() const {return m_nError;}

protected:
    virtual BOOL SendString(LPCTSTR lpStr, int nLen);

    int m_nType;
    int m_nPort;
    int m_nError;

    HANDLE m_hPort;
    OVERLAPPED m_oWrite;
    OVERLAPPED m_oRead;
    int m_nParity;
};

class CPT900 : public CPOSPrinter
{
public:
    CPT900(int nPort);
    virtual ~CPT900() {}

    virtual BOOL Initialize();
};

class CPOS88VI : public CPOSPrinter
{
public:
    CPOS88VI(int nPort);
    virtual ~CPOS88VI() {}

    virtual BOOL Initialize();
    
    virtual void SetPrintMode(int nMode);

    virtual void SetUnderline(int nUL);

    virtual void EnablePrinter(BOOL bEnable = TRUE);

    virtual void CutPaper(int nMode);

    virtual void EnableBold(BOOL bEnable = TRUE);
};

class CPR58 : public CPOSPrinter
{
public:
    CPR58(int nPort);
    virtual ~CPR58() {}
    virtual BOOL Initialize();

     virtual void PrintandFeed(LPCTSTR pStr, int nLength, int nFeed);
     virtual void SetDefualLineHight();
     virtual void SetLineHeight(int nHeight);

     virtual void SetPrintMode(int nMode);
     void EnableDoubleWidth();
     void DisableDoubleWidth();

     virtual void EnableUserFontSet(BOOL bEnable = TRUE);
     
     virtual void EnableButton(BOOL bEnable = TRUE);

     virtual void OpenCashdrawer(int nOpenInter  = 0, int nCloseInter = 0);

     virtual int QureyCashdrawerStatus();

     virtual BOOL QueryStatus(int nUnit, int &nError);
};
